import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: () => import('@/views/List.vue'),
      meta: { title: "列表页" }
    },
    {
      path: '/book/:id',
      meta:{title:'编辑'},
      component: () => import('@/views/BookAddOrEdit.vue'),
    },
    {
      path: '/book',
      meta:{title:'新增'},
      component: () => import('@/views/BookAddOrEdit.vue'),
    },
  ],
})
router.beforeEach((to, next) => {
  if (to.path && to.meta.title) {
    document.title = to.meta.title
  }
  else{
    next()
  }
})
export default router
